package com.maya.controller;

import javax.servlet.http.HttpSession;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.maya.model.User;
import com.maya.service.UserService;

@Controller

public class FollowUserController  {

	@Autowired
	private UserService userService;

	@ResponseBody
	@RequestMapping("/followuser")
	public String followuser(String viewedid,HttpSession session) {

		User user = (User)session.getAttribute("currUser");

		User viewedUser = userService.get(new ObjectId(viewedid));

		if(null == user) {

			return "----fail: not a logined user---";
		}
		userService.followPerson(user,viewedUser);

		return "OK";
	}
}
